# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=audaspace
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=3
pkgdesc="A high level audio library written in C++ with language bindings for Python (mingw-w64)"
arch=('any')
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-libsndfile"
         "${MINGW_PACKAGE_PREFIX}-openal"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-SDL2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
url="https://audaspace.github.io/"
source=(${_realname}-${pkgver}.tar.gz::https://github.com/audaspace/audaspace/archive/v${pkgver}.tar.gz
        0001-Fix-for-seeking-with-modified-pitch.patch
        0002-Bugfix-for-building-with-gcc7.patch
        0003-Make-fftw3-optional.patch
        0004-Build-option-configure-whether-to-build-versioned-pl.patch
        0005-Support-newer-ffmpeg-versions.patch
        0006-Udpate-for-travis.ci.patch
        0007-Some-fixes-backported-from-Blender.patch
        0008-Silence-some-warnings.patch
        0009-Bugfix-memory-leak-in-python-API.patch
        0010-OpenAL-recreate-device-if-disconnected.patch
        0011-Bugfix-don-t-add-non-existing-devices-to-the-device-.patch
        0012-Adding-a-modulator-sound-effect.patch
        0013-Bugfix-Return-correct-length-for-modulator-and-super.patch
        0014-Add-sample-rate-parameter-to-silence-generation.patch
        0015-Minor-CMakeLists.txt-formatting-fixes.patch
        0016-Fix-Missing-include-in-FileManager.h.patch
        0017-Bugfix-Fading-from-full-volume.patch
        0018-Bug-fixes-for-files-with-more-than-8-channels.patch
        0019-Bugfix-for-invalid-offsets-provided-by-ffmpeg-s-seek.patch
        0020-Docs-Use-class-methods-for-api-docs.patch
        0021-Docs-Cleanup-Line-Wrapping-for-python-examples.patch
        0022-Mixer-sample-buffer-added-channels-twice.patch
        0023-API-All-times-are-now-double-instead-of-float.patch
        0024-Fix-documentation-warnings.patch
        0025-Porting-fixes-from-blender.patch
        0026-Some-more-changes-of-times-from-flaot-to-double.patch
        0027-Trying-to-fix-Travis-CI-build-for-OS-X.patch
        0028-SDL-2-support-more-audio-formats.patch
        0029-Fix-corrupted-document-in-python-bindings.patch
        0030-Bugfix-JOS-resampling-type-bugfix-caused-integer-und.patch
        0031-Fix-numpy-import.patch
        0032-Add-callback-for-mixing-down-audio.patch
        0033-Fix-API-docs-for-python-playback-manager-play-functi.patch
        0034-Bugfix-more-accurate-positioning-of-sequences.patch
        0035-Bugfix-for-unwanted-volume-fading-at-the-beginning-o.patch
        0100-mingw-relocate.patch
        0101-mingw-exports.patch)
options=('!strip' 'staticlibs')
sha256sums=('20f6669ca0b9403cdf0b21141a494315d153ad00afccaad72c2e4e86586591d2'
            'de00a1a8b2f2dec930d34b3c09b8bdfb9044ce7668abf46ef87e716bca3429ed'
            '6e4005a07a24035240ccccca117cb36adc0488308163929c8dc556bc68bf21d6'
            '76d048e2b454ad523cd3e27c63495819f746511fbb410b6c1017d23ff7784d3f'
            '581c5501453f0c676161998a9686d5ffd2c178a1a1e5326f31724188631899bf'
            'b8d7c3090504117151f134240aea387199544fd6ec54e0b631e41d0395bdf33b'
            '42f16f8d5390c8a433045ebf436520590bb7bb2fc33701b484765eeb2e70953c'
            '2a6e9ce1d89a0586e8fc44b8a932bfd61e6316fe97a0602d12017e9093da6a9e'
            '4953097e66f8edf47911fb00e33c7bd54c77ee7f28005c47c7a0be192fa16345'
            '3f23603a9ff1bb8855a4fef385322a805de7d22ea672b38f87d29e01a4c9e311'
            'd3db2fda291aa29b4da92591d11ffec4cbbe9ef4ead4bef1489408fcb797eb89'
            '66ec0bb31aa20b759bf88ab34fef59c6f62c9394fd5aa7a0210d0d0c250775b2'
            '895e39489a3734ce1291036a2ef74c1d5ccd0ab825386653e211783680df1178'
            '60b2737deae6ec7660d8d23ff4b4ebe3f2bd410c1fbc0b9455805208b3b745e1'
            'f4d78420064784a52cb0db3a9e0983c9c6c3105a13e6540e4c26fa391f8ebae2'
            '6057850e3360557e320eb5c483159cac04773f00f2ed392e9ea38a98128b6204'
            '5584af56a6bf8b3a7a3778f2a704bad55309b8795a74fd8bd2401eaa4cde9d9b'
            'd2ae27a6d9a3b171b213b310a8ec75003372216c548ef4d1c76c061953101081'
            '68d6856dac8fed074e93537fc3767c7b13baafabc7eeff42f2309b8b77c8e7a5'
            '40b9dc1c9a6b891bdf46696654ec0220e75ff00709b4885a3c61d8db2b9cd7c7'
            '2ce335ad53e7d2757d7bc7f87e6618d4c62be69ef0cf6d20aa2a7147689393f8'
            'c322f91e7e773b9f13adb4e69263070d1d5ce91b43c07e713add9f377b567327'
            '964a15421b4de8dfd3a14a344baf2b6faccafde98bbbf5c730229b41a1f1ffd2'
            '77dc534a6f55f0e2dec6bc18904fb3b69249cd94ee540a46909afcb791d242ce'
            '5894d08fafe1fc872b5a18ad3dcd85edda26c5427e06d1e8209dc7a35fc57dd9'
            '19c7e59b000e980053c96f0cd5ab19cc308712a9b8fafba2e76905c2f7c1ea72'
            'becbbf6740f5170705f78a55785f60320aa369c22d2eaba5debe44bdae0a1290'
            'd5b6449bb1d57281640c9f048176b94d959657b1225d702b03c9ac88783eb3b0'
            'c9a7244e770d0abcd032be464636a45c04baf17a27fecb9d178b00a2d435fcfb'
            '08e5e89deb678a452cf011fd60d277f269a2522df11430d8fe162b08e3ad767c'
            '47097b08cf797db58e5450749569a6e54ed7b18236645a651f1e70f7d2e89e70'
            '540c98b3f0028e25fd22a9cf79e2ee5a5da33df9ad3d40a6f8c463381b63ec60'
            'ff4dcdc6cb4e854b2691e9ce73764adf029b28ef054956b7caee0273a25263cd'
            '40f040323d14e66e7afed44b21cb10ce8e27c125b8aa46cd2ff998c08eaaa6fa'
            '4835c16784ebdf4471457f29225e61f8d571eab82808b8d2175a14214cf1cbe8'
            '2507ee3ab3bbf25bc787a4946ffbd21a053a2bad9f2a5b7dacf4e6adef1c7096'
            'cc68bcc7154c1b06e96e86c587aeafbd6befa5538cf813ee5c42a3ccc13e357d'
            '8cf2aefb1973177ec3d75443e47ba95c66ca113076e615af0a8f6c8de1398da0')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}-${pkgver}
  
  apply_patch_with_msg \
    0001-Fix-for-seeking-with-modified-pitch.patch \
    0002-Bugfix-for-building-with-gcc7.patch \
    0003-Make-fftw3-optional.patch \
    0004-Build-option-configure-whether-to-build-versioned-pl.patch \
    0005-Support-newer-ffmpeg-versions.patch \
    0006-Udpate-for-travis.ci.patch \
    0007-Some-fixes-backported-from-Blender.patch \
    0008-Silence-some-warnings.patch \
    0009-Bugfix-memory-leak-in-python-API.patch \
    0010-OpenAL-recreate-device-if-disconnected.patch \
    0011-Bugfix-don-t-add-non-existing-devices-to-the-device-.patch \
    0012-Adding-a-modulator-sound-effect.patch \
    0013-Bugfix-Return-correct-length-for-modulator-and-super.patch \
    0014-Add-sample-rate-parameter-to-silence-generation.patch \
    0015-Minor-CMakeLists.txt-formatting-fixes.patch \
    0016-Fix-Missing-include-in-FileManager.h.patch \
    0017-Bugfix-Fading-from-full-volume.patch \
    0018-Bug-fixes-for-files-with-more-than-8-channels.patch \
    0019-Bugfix-for-invalid-offsets-provided-by-ffmpeg-s-seek.patch \
    0020-Docs-Use-class-methods-for-api-docs.patch \
    0021-Docs-Cleanup-Line-Wrapping-for-python-examples.patch \
    0022-Mixer-sample-buffer-added-channels-twice.patch \
    0023-API-All-times-are-now-double-instead-of-float.patch \
    0024-Fix-documentation-warnings.patch \
    0025-Porting-fixes-from-blender.patch \
    0026-Some-more-changes-of-times-from-flaot-to-double.patch \
    0027-Trying-to-fix-Travis-CI-build-for-OS-X.patch \
    0028-SDL-2-support-more-audio-formats.patch \
    0029-Fix-corrupted-document-in-python-bindings.patch \
    0030-Bugfix-JOS-resampling-type-bugfix-caused-integer-und.patch \
    0031-Fix-numpy-import.patch \
    0032-Add-callback-for-mixing-down-audio.patch \
    0033-Fix-API-docs-for-python-playback-manager-play-functi.patch \
    0034-Bugfix-more-accurate-positioning-of-sequences.patch \
    0035-Bugfix-for-unwanted-volume-fading-at-the-beginning-o.patch \
    0100-mingw-relocate.patch \
    0101-mingw-exports.patch
}

build() {
  declare -a _btype
  if check_option "debug" "y"; then
    _btype=Debug
  else
    _btype=Release
  fi

  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_btype} \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}//build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} -j1 install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
